﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Dynamic;
using System.ComponentModel;
using CCH.Entity;

namespace CCH.DAO
{
    [DataObject(true)]
    public class peopleDAO
    {
        private Entities model = new Entities();

        public int Get_Check(string login_id)
        {
            return (from d in model.people
                    where d.peo_login == login_id && d.state == "1"
                    select d).Count();
        }

        public int Get_Check_NotMe(string login, int peo_uid)
        {
            return (from d in model.people
                    where d.peo_login == login && d.peo_uid != peo_uid
                    select d).Count();
        }

        public people Get_people(string login_id, string login_pw)
        {
            return (from d in model.people
                    where d.peo_login == login_id && d.peo_passwd == login_pw && d.state == "1"
                    select d).FirstOrDefault();
        }

        public people Get_people(int peo_uid)
        {
            return (from d in model.people
                    where d.peo_uid == peo_uid
                    select d).FirstOrDefault();
        }

        public string Get_peopleName(int peo_uid)
        {
            return (from d in model.people where d.peo_uid == peo_uid select d.peo_name).FirstOrDefault();
        }

        public IQueryable<people> Get_people_AllData()
        {
            return from d in model.people
                   where d.state == "1"
                   orderby d.peo_uid
                   select d;
        }

        public IQueryable<people> Get_people_AllData(int startRowIndex, int maximumRows)
        {
            return Get_people_AllData().Skip(startRowIndex).Take(maximumRows);
        }

        public int Get_people_AllData_Count()
        {
            return Get_people_AllData().Count();
        }

        public void Add_people(people d)
        {
            model.people.AddObject(d);
            Update();
        }

        public void Delete_people(int uid, int peo_uid)
        {
            people d = Get_people(uid);
            d.state = "2";
            d.createuid = peo_uid;
            d.createtime = DateTime.Now;
            Update();
        }

        public void Update()
        {
            model.SaveChanges();
        }

    }

}
